class CreateUser {
    constructor (name) {
        this.name = name;
        this.getName();
    }
    getName() {
        return this.name;
    }
}
// 代理实现单例模式
const ProxyMode = (function () {
    let instance = null;
    return function (name) {
        if (!instance) {
            instance = new CreateUser(name);
        }
        return instance;
    }
})();
// 测试单体模式的实例
var a = new ProxyMode("aaa");
var b = new ProxyMode("bbb");
// 因为单体模式是只实例化一次，所以下面的实例是相等的
console.log(a === b);    //true



//
class SingleInstance {
    static instance = null
    constructor () {
        if (SingleInstance.instance !== null) {
            return SingleInstance.instance
        } else {
            SingleInstance.instance = this
        }
    }
}

var a = new SingleInstance("aaa");
var b = new SingleInstance("bbb");

console.log(a === b);